CWD = $(shell pwd)

# Add the names of your source files here.
PROJECT_FILES = _main MyGame StateMain StateTitle Physics Camera \
HeroClass TestEnemy MapData CollisionObject BaseEnemy BaseUnit UnitArray \
Decryptor Level Factory BaseTrigger LevelExitTrigger TriggerArray \
TimedJumpRunLevel PushLevelExitTrigger PopLevelExitTrigger LevelList \
StatefulSprite StatefulUnit
PENJIN_FILES = AnimatedParticle AnimatedSprite Animation AnimationMenuItem AnimationStringMenuItem Background BaseState CollisionMap Colour Command CountDown Emitter Encryption Engine GFX HiScore Image ImageMenuItem ImageStringMenuItem IntVector2d KeyMap KeyMapDigitalJoyAxis KeyMapHat KeyMapJoyAxis KeyMapJoyButton KeyMapMouseAxis KeyMapMouseButton KeyMapSDLKey KeyMapper LUT MMUHack Menu MenuItem Music NumberUtility Parser Particle ParticleCollider ParticleMirror PenjinFixedFunc Pixel Random Rectangle Score ScoreScreen ScreenPartition SimpleJoy Sound Sprite SpriteParticle StarField StringMenuItem StringUtility TextDoc Text TileMap Timer Variable Vector2df Vector2di Vector2dx Vector3d Vector3df Vector3di Vector3dx WiiJoy trenki/fixed_func
TOMCRYPT_FILES = aes crypt_argchk crypt_cipher_descriptor crypt_cipher_is_valid crypt_find_cipher_any crypt_find_cipher_id crypt_find_cipher crypt_find_hash_any crypt_find_hash_id crypt_find_hash crypt_find_hash_oid crypt_find_prng crypt_fsa crypt_hash_descriptor crypt_hash_is_valid crypt_ltc_mp_descriptor crypt_prng_descriptor crypt_prng_is_valid crypt_register_cipher crypt_register_hash crypt_register_prng crypt_unregister_cipher crypt_unregister_hash crypt_unregister_prng ctr_decrypt ctr_done ctr_encrypt ctr_getiv ctr_setiv ctr_start ctr_test error_to_string hash_memory rng_get_bytes rng_make_prng sha256 sprng yarrow zeromem
#TOMCRYPT_FILES = aes aes_tab cbc_decrypt cbc_done cbc_encrypt cbc_getiv cbc_setiv cbc_start crypt_argchk crypt crypt_cipher_descriptor crypt_cipher_is_valid crypt_find_cipher_any crypt_find_cipher crypt_find_cipher_id crypt_find_hash_any crypt_find_hash crypt_find_hash_id crypt_find_hash_oid crypt_find_prng crypt_fsa crypt_hash_descriptor crypt_hash_is_valid crypt_ltc_mp_descriptor crypt_prng_descriptor crypt_prng_is_valid crypt_register_cipher crypt_register_hash crypt_register_prng crypt_unregister_cipher crypt_unregister_hash crypt_unregister_prng ctr_decrypt ctr_done ctr_encrypt ctr_getiv ctr_setiv ctr_start ctr_test encrypt error_to_string hash_memory rng_get_bytes rng_make_prng sha224 sha256 small sprng yarrow zeromem

PROJECT_OBJ_FILES = $(addsuffix .o, $(PROJECT_FILES))
PENJIN_OBJ_FILES = $(addprefix PenjinBase/, $(addsuffix .o, $(PENJIN_FILES)))
TOMCRYPT_OBJ_FILES = $(addprefix tomcrypt/, $(addsuffix .o, $(TOMCRYPT_FILES)))
OBJ_FILES = $(PROJECT_OBJ_FILES) $(PENJIN_OBJ_FILES) $(TOMCRYPT_OBJ_FILES)


# The compiler options to specify
COMPILER_OPTIONS = -O2 -DPLATFORM_PC -D_LINUX_ -DPENJIN_SDL -I '$(CWD)/PenjinBase/' -I '$(CWD)' -I '$(CWD)/tomcrypt'
DEBUG_COMPILER_OPTIONS = -g $(EXTRACFLAGS) -D_DEBUG -DPLATFORM_PC -D_LINUX_ -DPENJIN_SDL -I '$(CWD)/PenjinBase/' -I '$(CWD)' -I '$(CWD)/tomcrypt'
CFLAGS += -I'$(CWD)/tomcrypt' -DLTC_SOURCE -O3 -funroll-loops
# The linker options to specify
LINKER_OPTIONS = -s `sdl-config --libs` -lX11 -lXi -lSDL_ttf -lSDL_image -lSDL_mixer -lSDL_gfx
DEBUG_LINKER_OPTIONS = `sdl-config --libs` -lX11 -lXi -lSDL_ttf -lSDL_image -lSDL_mixer -lSDL_gfx

# The rule for building a .o file from a .cpp file
%.o: %.cpp
ifeq ($(DEBUG),true)
	c++ -c $(DEBUG_COMPILER_OPTIONS) $< -o $@
else
	c++ -c $(COMPILER_OPTIONS) $< -o $@
endif

# The rule for building a .o file from a .c file
%.o: %.c
ifeq ($DEBUG),true)
	cc -c -g $(CFLAGS) $< -o $@
else
	cc -c $(CFLAGS) $< -o $@
endif

# The name of the executable.
BIN_FILE = built/wandor

# The main target to build the executable.
exec: $(OBJ_FILES)
ifeq ($(DEBUG),true)
	c++ $(OBJ_FILES) $(DEBUG_LINKER_OPTIONS) -o $(BIN_FILE)
else
	c++ $(OBJ_FILES) $(LINKER_OPTIONS) -o $(BIN_FILE)
endif

# Default target for Eclipse
all: exec

# Debug target
debug: DEBUG = true
debug: exec

# A cleanup target to remove object files, backups, and the executable.
clean:
	$(RM) $(RMFL) $(OBJ_FILES) $(BIN_FILE) *~
	$(RM) $(RMFL) $(DBGOBJ_FILES) $(DBGBIN_FILE) *~

